//该文件用于创建Vuex中最为核心的store

//引入Vuex
import Vuex from 'vuex'
//引入Vue
import Vue from 'vue'
//使用vuex
Vue.use(Vuex)
//准备actions 用于响应组件中的动作
const actions = {
    isFlag(context, value) {
        //处理逻辑...
        context.commit('ISFLAG', value)
    },
    getUniversityLength(context, value) {
        //处理逻辑...
        context.commit('GETUNIVERSITYLENGTH', value)
    },
    giveUniList(context, value) {
        //处理逻辑...
        context.commit('GIVEUNILIST', value)
    },
    mbtiTest(context, value) {
        //处理逻辑...
        context.commit('MBTITEST', value)
    },
    answers(context, value) {
        context.commit('ANSWERS', value)
    },
    setAnswersNull(context,value){
        context.commit('SETANSWERSNULL',value)
    }
}
//准备mutations 用于操作数据
const mutations = {
    ISFLAG(state, value) {
        //处理逻辑
        state.flag = value
    },
    GETUNIVERSITYLENGTH(state, value) {
        state.universityLength = value
    },
    GIVEUNILIST(state, value) {
        state.uniList = value
    },
    MBTITEST(state, value) {
        state.mbtiTest = value
    },
    ANSWERS(state, value) {
        state.answers += value + ','
    },
    SETANSWERSNULL(state,value){
        state.answers = value
    },
    SAVEHOTUNIVERSITY(state,value){
        state.hotUniversity = value
    },
    HANDLEHOTFLAG(state,value){
        state.hotFlag = false
    },
    RADIOBTN(state,value){
        state.radioBtn += value
    },
    RADIOBTNNULL(state,value){
        state.radioBtn = value
    },
    SIGNUPINFO(state,value){
        state.signUsername = value.username
        state.signPassword = value.password
    },
    HOTNULL(state,value){
       state.hotUniversity = value
    }
}
//准备state 用于存储数据
const state = {
    flag: false,
    universityLength: 0,
    uniList: [],
    mbtiTest: {},
    answers: '',
    hotUniversity:[],
    hotFlag:true,
    radioBtn:0,
    signUsername:'',
    signPassword:''
}

//准备getters，用于将state中的数据进行加工
const getters = {
    finalAnswers(state){
        let str = state.answers
        return str.substring(0,str.length - 1)
    }
}

//创建store并暴露
export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})